//
//  C_MVCollectionViewCell.m
//  音悦咖
//
//  Created by Best on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_MVCollectionViewCell.h"

@implementation C_MVCollectionViewCell

- (void)dealloc
{
    [_mainImageView release];
    [_mainView release];
    [_dayTitleLabel release];
    [_monthTitleLabel release];
    [_model release];
    [_descLabel release];
    [_tagLabel release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}


- (void)create
{
    
    self.mainImageView  = [[UIImageView alloc] init];
    [self addSubview:self.mainImageView];
    [_mainImageView release];
    
    self.mainView = [[UIView alloc] init];
    [self.mainImageView addSubview:self.mainView];
    [_mainView release];
    
    self.dayTitleLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.dayTitleLabel];
    [_dayTitleLabel release];
    
    self.monthTitleLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.monthTitleLabel];
    [_monthTitleLabel release];
    
    self.placeLabel = [[UILabel alloc] init];
    [self.mainView addSubview:self.placeLabel];
    [_placeLabel release];
 
    
    self.descLabel = [[UILabel alloc] init];
    self.descLabel.font = [UIFont systemFontOfSize:15];
    self.descLabel.numberOfLines = 0;
    [self.mainView addSubview:self.descLabel];
    [_descLabel release];
    
    
    for (NSInteger i = 0; i < 3; i++) {
        label = [[UILabel alloc] init];
        [self.mainView addSubview:label];
        label.tag = 10000 + i;
        [label release];
    }
    
   
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.mainImageView.frame = layoutAttributes.bounds;
    self.mainView.frame = CGRectMake(0, self.mainImageView.frame.size.height - 60, self.mainImageView.frame.size.width, 60);
    self.dayTitleLabel.frame = CGRectMake(10, 3, 40, self.mainView.frame.size.height / 2 -3);
    self.dayTitleLabel.textColor = [UIColor whiteColor];
    self.dayTitleLabel.font = [UIFont systemFontOfSize:20];
    self.mainView.backgroundColor = RGBA(71, 71, 71, 0.6);
//    self.mainView.alpha = 0.7;
    self.placeLabel.frame = CGRectMake(5, self.dayTitleLabel.frame.origin.y + self.dayTitleLabel.frame.size.height, self.dayTitleLabel.frame.size.width - 5, 1);
    [self.placeLabel.layer setBorderWidth:1];
    [self.placeLabel.layer setBorderColor:[[UIColor blackColor] CGColor]];
    
    self.monthTitleLabel.frame = CGRectMake(10, self.placeLabel.frame.size.height + self.placeLabel.frame.origin.y, self.placeLabel.frame.size.width, self.dayTitleLabel.frame.size.height - 2);
    self.monthTitleLabel.textColor = [UIColor whiteColor];
    self.descLabel.frame = CGRectMake(self.dayTitleLabel.frame.size.width + self.dayTitleLabel.frame.origin.x + 10, 5, self.mainImageView.frame.size.width - (self.dayTitleLabel.frame.size.width + self.dayTitleLabel.frame.origin.x + 10) - 10, 30);
    self.descLabel.textColor = [UIColor whiteColor];
    for (NSInteger i = 0; i < 3; i++) {
        label = (UILabel *)[self viewWithTag:10000 + i];
        label.frame = CGRectMake(self.monthTitleLabel.frame.size.width + self.monthTitleLabel.frame.origin.x + 10 + 50 * i + 20, self.mainView.frame.size.height - 13, 50, 10);
        
    }
    
    
}


- (void)setModel:(MVModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.mainImageView setImageWithURL:model.bigPicUrl placeholderImage:[UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"place", @"jpg")]];
    NSArray *strArr = [model.title componentsSeparatedByString:@"/"];
    self.dayTitleLabel.text = strArr[0];
    self.monthTitleLabel.text = [strArr[1] stringByAppendingString:@"月"];
    self.descLabel.text = model.desc;
    [self.descLabel sizeToFit];
    
    for (NSInteger i = 0; i < model.tag.count; i++) {
      label = (UILabel *)[self viewWithTag:10000 + i];
    
        label.text = [model.tag[i] objectForKey:@"tagName"];
        label.font = [UIFont systemFontOfSize:13];
        NSString *str = [[model.tag[i] objectForKey:@"tagColor"] substringWithRange:NSMakeRange(4, 11)];
        NSArray *color = [str componentsSeparatedByString:@","];
        label.textColor = RGBA([color[0] floatValue], [color[1] floatValue], [color[2] floatValue], 1);
        label.textAlignment = NSTextAlignmentCenter;
        
    }
  
}







@end
